home *** CD-ROM | disk | FTP | other *** search
/ Singles Flirt Up Your Life! (German) / Singles Flirt Up Your Life.iso / data1.cab / Statemachine / armchair.lua < prev    next >
Text File  |  2004-01-29  |  2KB  |  79 lines

  1. -- armchair state machine
  2.  
  3. beginStateMachine()
  4.  
  5.     onMsg("buildMenu", function(msg)
  6.         if (repairMenu()) then return end
  7.         
  8.         -- build the pie menu
  9.         clearPieMenu();
  10.         local button ;
  11.         button = addPieMenuButton("pm_sitdown", "sit");
  12.         button.addDescription(ACTIVITY, "sit");
  13.         -- button.addIcon("guiIconComfort");
  14.     end )
  15.     
  16.     -- sit on armchair
  17.     onMsg("sit", function(msg)
  18.         -- get the game object server
  19.         local gameObjectServer = getGameObjectServer();
  20.         -- get character who initiated this action
  21.         local character = getStateObjectFromID(msg.sender);
  22.         -- if this is broken: abort characters action
  23.         if abortIfBroken(character) then return end;        
  24.         
  25.         -- walk to the closest action point
  26.         local actionPoint = character.getFreeActionPoint(this, "sit");
  27.         -- get the walk state object
  28.         local wso = character.walkSO;
  29.         if (actionPoint) then
  30.             -- create state machine contexts
  31.             local wsoContext = StateMachineContext();
  32.             -- store the action point
  33.             wsoContext.storeData("actionPointName", actionPoint.getName());
  34.             if (wso.walkToActionPoint(actionPoint)) then
  35.                 --wso.queueStateMachine("armchairChar.sitDown", this, wsoContext);
  36.                 wso.queueStateMachine("sofaChar.sitDown", this, wsoContext);
  37.             else
  38.                 print("no path found");
  39.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  40.             end
  41.         else
  42.             print("no action point found");
  43.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  44.         end
  45.     end )
  46.     
  47.     
  48.     -- repair
  49.     onMsg("repair", function(msg)
  50.     
  51.         print("onMsg repair");
  52.         -- get character who initiated this action
  53.         local character = getStateObjectFromID(msg.sender);
  54.         -- walk to the closest action point
  55.         local actionPoint = character.getFreeActionPoint(this, "repair");
  56.         -- get the walk state object
  57.         local wso = character.walkSO;
  58.         if (actionPoint) then
  59.             -- create state machine contexts
  60.             local wsoContext = StateMachineContext();
  61.             -- store the action point
  62.             wsoContext.storeData("actionPointName", actionPoint.getName());
  63.             if (wso.walkToActionPoint(actionPoint)) then
  64.                 wso.queueStateMachine("repairChar.repairStart", this, wsoContext);
  65.             else
  66.                 print("no path found");
  67.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  68.             end
  69.         else
  70.             print("no action point found");
  71.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  72.         end
  73.     end )
  74.     
  75.  
  76.  
  77.             
  78. endStateMachine()
  79.